defmodule Pango.DeeprScriptInit do
    @moduledoc """
        使用deepr要初始化数据库的操作
    """
    alias Pango.PgSqlDb


    def init_pg_script(repo) do
        Enum.each(pg_script(), &PgSqlDb.run(repo, &1))
    end

    def pg_script() do
        [
            """
            -- 创建 deepr 分页函数, 不然用不了 UNION ALL
            CREATE OR REPLACE FUNCTION get_deepr_list(sql text)
            RETURNS record AS $$
                DECLARE
                result record;
                BEGIN
                    EXECUTE sql INTO result;
                    RETURN result;
                END;
            $$ LANGUAGE plpgsql;
            """
        ]
    end

end
